<script>

    /**
     *
     *
     */
    function click_event(link)
    {
        alert(link.href);
    }

</script>
<?php

    if (!(isset($_GET['valid']) && $_GET['valid']))
    {
        return;
    }

    // Does the key value to search is set, otherwise stop the software
    // right here.
    if (!isset($_GET['key']))
    {
        return;
    }

    $key = $_GET['key'];

    // Read information on the data base
    $database = new mysqli('localhost', 'obx', 'obx', 'obx');

    // Does the connection be established with the database.
    if ($database->connect_errno)
    {
        return;
    }

    // Initialize the result variables.
    $result = null;

    $sql = 'SELECT id,name,mark,model,price FROM obx.product WHERE name like \'%'.$key.'%\' OR mark like \'%'.$key.'%\' OR model like \'%'.$key.'%\' ORDER BY id DESC LIMIT 6;';

    if (!$result = $database->query($sql))
    {
        return;
    }

/*
 * Return the products actoin
 */
    echo '<tr><td><h1 id="auto_complete_title" class="auto_complete_title">Searching:</h1></td></tr>';
    while ($entry = $result->fetch_assoc())
    {
        // Get the variables
        $model = str_replace(' ', '_', $entry['model']);
        $name  = strtolower($entry['name']);

        echo '<tr>';
        echo '<td>';
        echo '<a href="products/'.$name.'/'.$model.'" onclick="return click_event(this);">';
        echo $entry['name'].': '.$entry['model'];
        echo '<span style="color: rgba(20, 20, 20, 0.5);"> ('.$entry['mark'].')</span>';
        echo '<span style="float: right; color:rgb(175, 30, 35); margin-right: 8px;">$'.$entry['price'].'</span>';
        echo '</a>';
        echo '</td>';
        echo '</tr>';
    }
?>
